#include <stdio.h>
#include <stdlib.h>

#define MAX_N 10

int	map[MAX_N+1][MAX_N+1]; 
int score[MAX_N+1][MAX_N+1][MAX_N+1][MAX_N+1]; 

int N;

#define max(a, b) ((a)>(b) ? (a) : (b))

void dump_map(void)
{
	int i,j; 
	
	printf("map matrix\n"); 
	for (i=1; i<=N; i++) {
		for (j=1; j<=N; j++) {
			printf("%6d ",  map[i][j]); 
		}
		printf("\n"); 
	}
	//getchar(); 
}

void dump_score(void)
{
	int i,j, k, l; 
	
	printf("map matrix\n"); 
	for (i=1; i<N; i++) {
		for (j=1; j<N; j++) {
			for (k=1; k<=N; k++) {
				for (l=1; l<=N; l++) {
					printf("score[%d][%d][%d][%d] = %6d\n",  i, j, k, l, score[i][j][k][l]); 
				}
			}
		}
	}
	//getchar(); 
}


// mark score for every point of the map
// trasfer expression: score[i][j][k][l] = map[i][j] + max(score[i-1][j][k-1][l], score[i][j-1][k-1][l], score[i-1][j][k][l-1], score[i][j-1][k][l-1])
int mark_score(void)
{
	int i,j, k, l; 
	
	for (i=1; i<=N; i++) {
		for (j=1; j<=N; j++) {
			for (k=1; k<=N; k++) {
				l = i + j - k; 
				if(l<=0)
                	break;
				score[i][j][k][l] = max(score[i-1][j][k-1][l], max(score[i][j-1][k-1][l], max(score[i-1][j][k][l-1], score[i][j-1][k][l-1])));
				if (i==k && j==l) {
					score[i][j][k][l] += map[i][j]; 
				} else {
					score[i][j][k][l] += map[i][j] + map[k][l]; 
				}
				//printf("score[%d][%d][%d][%d] = %6d, map[%d][%d]=%d, map_kl=%d\n",  i, j, k, l, score[i][j][k][l], i, j, map[i][j],  map[k][l]); 
			}
		}
	}
	//dump_score(); 
	return score[N][N][N][N]; 
}



int main()
{
	int	i, j, s; 
	int	total; 
	scanf("%d", &N); 
	while(1) {
		scanf("%d %d %d", &i, &j, &s); 
		if (i==0 && j==0 && s==0)
			break; 
		map[i][j] = s; 
		//printf("i=%d, j=%d, s=%d\n", i, j, s);  
	}
	//dump_map(); 
	total = mark_score(); 
	printf("%d\n", total); 
	return 0; 
}





